﻿ #region Disclaimer/Info
 
 /////////////////////////////////////////////////////////////////////////////////////////////////
 //
 //   File:		NHibernateExtensions.cs
 //   Website:		http://dexterblogengine.com/
 //   Authors:		http://dexterblogengine.com/About.ashx
 //   Rev:		1
 //   Created:		19/01/2011
 //   Last edit:		19/01/2011
 //   License:		GNU Library General Public License (LGPL)
 //   File:            NHibernateExtensions.cs
 //   For updated news and information please visit http://dexterblogengine.com/
 //   Dexter is hosted to Codeplex at http://dexterblogengine.codeplex.com
 //   For any question contact info@dexterblogengine.com
 //
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
 #endregion

using System.Collections.Generic;
using NHibernate;
using NHibernate.Engine;

namespace Dexter.Repository.NHibernate.Extensions {

	internal static class NHibernateExtensions {
		/// <summary>
		/// Registers the query query to the <see cref="NamedQueryDefinition"/>.
		/// </summary>
		/// <param name="queries">The queries.</param>
		/// <param name="hql">The HQL.</param>
		/// <param name="queryKey">The query key.</param>
		public static void RegisterQuery ( this IDictionary <string , NamedQueryDefinition> queries , string hql , string queryKey ) {
			RegisterQuery ( queries , hql , queryKey , false , null );
		}

		/// <summary>
		/// Registers the query query to the <see cref="NamedQueryDefinition"/>.
		/// </summary>
		/// <param name="queries">The queries.</param>
		/// <param name="hql">The HQL.</param>
		/// <param name="queryKey">The query key.</param>
		/// <param name="cacheable">if set to <c>true</c> [cacheable].</param>
		/// <param name="cacheRegion">The cache region.</param>
		public static void RegisterQuery ( this IDictionary <string , NamedQueryDefinition> queries , string hql , string queryKey , bool cacheable , string cacheRegion ) {
			var query = new NamedQueryDefinition ( hql ,
			                                       cacheable ,
			                                       cacheRegion ,
			                                       10 ,
			                                       0 ,
			                                       FlushMode.Auto ,
			                                       false ,
			                                       null ,
			                                       null
				);

			queries.Add ( new KeyValuePair <string , NamedQueryDefinition> ( queryKey , query ) );
		}
	}
}
